package per.dg.tencent.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import per.dg.tencent.R;
import per.dg.tencent.databinding.ItemRvBannerBinding;
import per.dg.tencent.databinding.ItemRvRvBinding;
import per.dg.tencent.databinding.ItemTitleBinding;
import per.dg.tencent.databinding.ItemVideoBinding;
import per.dg.tencent.model.VideoModel;

public class VideoRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    Context mContext;
    List<VideoModel> mList;

    public VideoRecyclerViewAdapter(Context mContext, List<VideoModel> mList){
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public int getItemViewType(int position) {
        String type = mList.get(position).getType();
        switch (type){
            case "banner":
                return 0;
            case "title":
                return 1;
            case "huizhui":
                return 2;
            case "redian":
                return 3;
            default:
                return 4;
        }
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if(viewType == 0){
            return new BannerViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_rv_banner, parent, false));
        }
        if(viewType == 1){
            return new TitleViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_title, parent, false));
        }
        if(viewType == 2){
            return new RecyclerViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_rv_rv, parent, false));
        }
        if(viewType == 3){
            return new VideoViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_video, parent, false));
        }
        return new VideoViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_video, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if(holder instanceof TitleViewHolder){

        }else if(holder instanceof VideoViewHolder){
//            if(position%2 == 0){
//                ((VideoViewHolder) holder).mItemVideoBinding.appImgVideo.setImageResource(R.mipmap.a);
//            }else {
//                ((VideoViewHolder) holder).mItemVideoBinding.appImgVideo.setImageResource(R.mipmap.b);
//            }
        }else if(holder instanceof BannerViewHolder){

        }else if(holder instanceof RecyclerViewHolder){
            ((RecyclerViewHolder) holder).mItemRvRvBinding.appRvLove.setAdapter(new VideoRecyclerViewAdapter(mContext, mList.get(position).getList()));
        }
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    public class BannerViewHolder extends RecyclerView.ViewHolder{

        ItemRvBannerBinding mItemRvBannerBinding;

        public BannerViewHolder(@NonNull View itemView) {
            super(itemView);
            mItemRvBannerBinding = ItemRvBannerBinding.bind(itemView);
        }
    }

    public class RecyclerViewHolder extends RecyclerView.ViewHolder{

        ItemRvRvBinding mItemRvRvBinding;

        public RecyclerViewHolder(@NonNull View itemView) {
            super(itemView);
            mItemRvRvBinding = ItemRvRvBinding.bind(itemView);
        }
    }

    public class VideoViewHolder extends RecyclerView.ViewHolder{

        ItemVideoBinding mItemVideoBinding;

        public VideoViewHolder(@NonNull View itemView) {
            super(itemView);
            mItemVideoBinding = ItemVideoBinding.bind(itemView);
        }
    }

    public class TitleViewHolder extends RecyclerView.ViewHolder{

        ItemTitleBinding mItemTitleBinding;

        public TitleViewHolder(@NonNull View itemView) {
            super(itemView);
            mItemTitleBinding = ItemTitleBinding.bind(itemView);
        }
    }

}
